#tag Class
Protected Class myTimer
Inherits Timer
	#tag Event
		Sub Action()
		  dim d As new date
		  dim remdr as Integer = FinishTime - d.TotalSeconds
		  dim elapsed As Integer = d.TotalSeconds - mStartTime
		  if remdr < 0 then
		    remdr = 0
		  end if
		  if elapsed <> mElapsed then
		    secsElapsed elapsed
		    mElapsed = elapsed
		  end if
		  if FinishTime >= 0 then
		    if remdr <> mRemaining then
		      secsLeft remdr
		      mRemaining = remdr
		    end if
		    if remdr = 0 then
		      Alarm
		      me.Enabled = False
		    end if
		  end if
		  
		End Sub
	#tag EndEvent


	#tag Method, Flags = &h0
		Sub reset(FinishAt As Date)
		  FinishTime = FinishAt.TotalSeconds
		  dim d As new Date
		  mStartTime = d.TotalSeconds
		  me.Enabled = True
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub Constructor(FinishAt As Date)
		  reset FinishAt 
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub Constructor()
		  Dim d As new Date
		  mStartTime = d.TotalSeconds
		End Sub
	#tag EndMethod


	#tag Hook, Flags = &h0
		Event secsLeft(secs As Integer)
	#tag EndHook

	#tag Hook, Flags = &h0
		Event Alarm()
	#tag EndHook

	#tag Hook, Flags = &h0
		Event secsElapsed(secs As Integer)
	#tag EndHook


	#tag Property, Flags = &h21
		Private FinishTime As Double
	#tag EndProperty

	#tag Property, Flags = &h21
		Private mRemaining As Integer = -1
	#tag EndProperty

	#tag Property, Flags = &h21
		Private mStartTime As Double = -1
	#tag EndProperty

	#tag Property, Flags = &h21
		Private mElapsed As Integer = -1
	#tag EndProperty


	#tag ViewBehavior
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Timer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			Type="Integer"
			InheritedFrom="Timer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Timer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InheritedFrom="Timer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InheritedFrom="Timer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Mode"
			Visible=true
			Group="Behavior"
			InitialValue="2"
			Type="Integer"
			EditorType="Enum"
			InheritedFrom="Timer"
			#tag EnumValues
				"0 - Off"
				"1 - Single"
				"2 - Multiple"
			#tag EndEnumValues
		#tag EndViewProperty
		#tag ViewProperty
			Name="Period"
			Visible=true
			Group="Behavior"
			InitialValue="300"
			Type="Integer"
			InheritedFrom="Timer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="FinishTime"
			Group="Behavior"
			InitialValue="0"
			Type="Double"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
